home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / sgverinf / FINDVERI.VBS < prev    next >
Text File  |  1998-08-10  |  5KB  |  152 lines

  1. '--------------------------------------------------------------------------
  2. ' FindVerInfo.vbs - Finds files which have specified string in the 
  3. '                   version information
  4. '
  5. '  SYNTAX: FindVerInfo path verinfo_name value
  6. '  
  7. '          path         - folder to be searched
  8. '          verinfo_name - name of the version item to search
  9. '          value        - value to search for
  10. '          
  11. '
  12. ' This file is part of the sgVersionInfo.
  13. ' Copyright (C) 1998 Stinga
  14. ' All rights reserved.
  15. '
  16. ' This source code demonstrates usage of the sgVersionInfo component
  17. '--------------------------------------------------------------------------
  18.  
  19. ' sgFileFlag constants
  20. const sgVS_FF_DEBUG           = &H00000001
  21. const sgVS_FF_PRERELEASE      = &H00000002
  22. const sgVS_FF_PATCHED         = &H00000004
  23. const sgVS_FF_PRIVATEBUILD    = &H00000008
  24. const sgVS_FF_INFOINFERRED    = &H00000010
  25. const sgVS_FF_SPECIALBUILD    = &H00000020
  26.  
  27. ' sgFileOS constants
  28. const sgVOS_UNKNOWN           = &H00000000
  29. const sgVOS_DOS               = &H00010000
  30. const sgVOS_OS216             = &H00020000
  31. const sgVOS_OS232             = &H00030000
  32. const sgVOS_NT                = &H00040000
  33. const sgVOS__BASE             = &H00000000
  34. const sgVOS__WINDOWS16        = &H00000001
  35. const sgVOS__PM16             = &H00000002
  36. const sgVOS__PM32             = &H00000003
  37. const sgVOS__WINDOWS32        = &H00000004
  38. const sgVOS_DOS_WINDOWS16     = &H00010001
  39. const sgVOS_DOS_WINDOWS32     = &H00010004
  40. const sgVOS_OS216_PM16        = &H00020002
  41. const sgVOS_OS232_PM32        = &H00030003
  42. const sgVOS_NT_WINDOWS32      = &H00040004
  43.  
  44. ' sgFileType constants
  45. const sgVFT_UNKNOWN           = &H00000000
  46. const sgVFT_APP               = &H00000001
  47. const sgVFT_DLL               = &H00000002
  48. const sgVFT_DRV               = &H00000003
  49. const sgVFT_FONT              = &H00000004
  50. const sgVFT_VXD               = &H00000005
  51. const sgVFT_STATIC_LIB        = &H00000007
  52.  
  53. ' sgFileSubtype constants
  54. const sgVFT2_UNKNOWN          = &H00000000
  55. const sgVFT2_DRV_PRINTER      = &H00000001
  56. const sgVFT2_DRV_KEYBOARD     = &H00000002
  57. const sgVFT2_DRV_LANGUAGE     = &H00000003
  58. const sgVFT2_DRV_DISPLAY      = &H00000004
  59. const sgVFT2_DRV_MOUSE        = &H00000005
  60. const sgVFT2_DRV_NETWORK      = &H00000006
  61. const sgVFT2_DRV_SYSTEM       = &H00000007
  62. const sgVFT2_DRV_INSTALLABLE  = &H00000008
  63. const sgVFT2_DRV_SOUND        = &H00000009
  64. const sgVFT2_DRV_COMM         = &H0000000A
  65. const sgVFT2_DRV_INPUTMETHOD  = &H0000000B
  66. const sgVFT2_FONT_RASTER      = &H00000001
  67. const sgVFT2_FONT_VECTOR      = &H00000002
  68. const sgVFT2_FONT_TRUETYPE    = &H00000003
  69.  
  70. On Error Resume Next
  71. Dim sKey, sValue, sFolder, sInfo, sMsg
  72. Dim vbCrLf
  73. vbCrLf = Chr(13) + Chr(10)
  74.  
  75. ' Are we running from command line
  76. Dim bFromCmdLine
  77. bFromCmdLine = false
  78. if InStrRev(UCase(WScript.FullName), "CSCRIPT") then bFromCmdLine = true
  79.  
  80. ' Check arguments
  81. if WScript.Arguments.Count <> 3 then
  82.     ' Command line does not contain arguments.
  83.     ' Retrieve arguments from the user
  84.     sFolder = InputBox("Enter folder to search:", "Folder")
  85.     if sFolder = "" then WScript.Quit(0)
  86.     sKey = InputBox("Enter key to search:", "Key", "CompanyName")
  87.     if sKey = "" then WScript.Quit(0)
  88.     sValue = InputBox("Enter value to search for:", "Value", "Stinga")
  89.     if sValue = "" then WScript.Quit(0)
  90. else
  91.     sFolder = WScript.Arguments(0)
  92.     sKey    = WScript.Arguments(1)
  93.     sValue  = WScript.Arguments(2)
  94. end if
  95. '    WScript.Echo "Invalid command line. Expected: "    + vbCrLf + "FindVerInfo path verinfo_name value"
  96. '    WScript.Quit(0)
  97. 'end if
  98.  
  99. ' Create some objects
  100. set VerInfo = WScript.CreateObject("sgVersionInfo.VersionInfo")
  101. Set fs      = WScript.CreateObject("Scripting.FileSystemObject")
  102.  
  103. if (Err.Number <> 0) then
  104.     Msg "Error: Unable to create SGVersionInfo or FileSystemObject object", 0, "Find Version Info Error"
  105.     WScript.Quit(0)
  106. end if
  107.  
  108. Set foldr = fs.GetFolder(sFolder)
  109.  
  110. ' Scan all files in the folder
  111. For Each file In foldr.Files
  112.  
  113.     ' Try to get version info for current file
  114.     VerInfo.Path = File.Path
  115.     if Err.Number = 0 then
  116.  
  117.         ' No error. Get specified info and see if specified value is in it
  118.         if VerInfo.InfoExist then
  119.             sInfo = VerInfo.GetValue("StringFileInfo", sKey)
  120.             if InStr(sInfo, sValue) > 0 then
  121.                 sMsg = file.Name + Chr(9) + VerInfo.FileVersion + Chr(9) + VerInfo.FileDescription
  122.                 rc = Msg(sMsg, 1, "Find Version Info")
  123.                 if rc = 2 then WScript.Quit(0)
  124.             end if
  125.         end if
  126.     else
  127.         ' Somethig went wrong
  128.         sMsg = "Error: " + file.Name + " - " + Err.Decription
  129.         Msg sMsg, 1, "Find Version Info Error"
  130.         Err.Clear
  131.     end if
  132. next
  133.  
  134. set VerInfo = nothing
  135. Set fs      = nothing
  136. Set foldr   = nothing
  137.  
  138. WScript.Quit(0)
  139.  
  140. function Msg(sText, nFlags, sTitle)
  141.     Msg = 0
  142.     if bFromCmdLine then
  143.         WScript.Echo sText
  144.     else
  145.         if sTitle <> "" then
  146.             Msg = MsgBox(sText, nFlags, sTitle)
  147.         else
  148.             Msg = MsgBox(sText, nFlags)
  149.         end if
  150.     end if
  151. end function
  152.